source("../../lib/som-utils.R")
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
source("../../lib/maps-utils.R")
Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
mpr.set_base_path_analysis()
model <- mpr.load_model("som-154.rds.xz")
summary(model)
SOM of size 5x5 with a hexagonal topology and a bubble neighbourhood function.
The number of data layers is 1.
Distance measure(s) used: sumofsquares.
Training data included: 156652 objects.
Mean distance to the closest unit in the map: 0.818.
plot(model, type="changes")
df <- mpr.load_data("datos_semana_2k.csv.xz")
df
summary(df)
id_estacion fecha fecha_cnt tmax
Length:156652 Length:156652 Min. : 1.00 Min. :-109.0
Class :character Class :character 1st Qu.:13.00 1st Qu.: 147.0
Mode :character Mode :character Median :27.00 Median : 201.0
Mean :26.53 Mean : 202.1
3rd Qu.:40.00 3rd Qu.: 262.0
Max. :53.00 Max. : 442.0
tmin precip nevada prof_nieve
Min. :-189.00 Min. : 0.00 Min. :0 Min. : 0.000
1st Qu.: 48.00 1st Qu.: 0.00 1st Qu.:0 1st Qu.: 0.000
Median : 98.00 Median : 3.00 Median :0 Median : 0.000
Mean : 98.13 Mean : 16.92 Mean :0 Mean : 0.604
3rd Qu.: 152.00 3rd Qu.: 20.00 3rd Qu.:0 3rd Qu.: 0.000
Max. : 272.00 Max. :690.00 Max. :0 Max. :1073.000
longitud latitud altitud
Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.:39.01 1st Qu.: -4.850 1st Qu.: 44.0
Median :41.22 Median : -1.411 Median : 263.0
Mean :40.05 Mean : -2.426 Mean : 478.5
3rd Qu.:42.19 3rd Qu.: 1.272 3rd Qu.: 687.0
Max. :43.57 Max. : 4.216 Max. :2535.0
world <- ne_countries(scale = "medium", returnclass = "sf")
spain <- subset(world, admin == "Spain")
plot(model, type="count", shape = "straight", palette.name = mpr.degrade.bleu)
NĂºmero de elementos en cada celda:
nb <- table(model$unit.classif)
print(nb)
1 2 3 4 5 6 7 8 9 10 11 12 13
11470 5939 8567 4263 3651 15037 4082 1697 10272 5205 6481 5617 2869
14 15 16 17 18 19 20 21 22 23 24 25
5990 10183 5900 6505 5168 5958 2881 11868 5240 9753 1699 357
ComprobaciĂ³n de nodos vacĂos:
dim_model <- 5*5;
len_nb = length(nb);
empty_nodes <- dim_model != len_nb;
if (empty_nodes) {
print(paste("[Warning] Existen nodos vacĂos: ", len_nb, "/", dim_model))
}
plot(model, type="dist.neighbours", shape = "straight")
model_colnames = c("fecha_cnt", "precip", "longitud", "latitud", "altitud")
model_ncol = length(model_colnames)
plot(model, shape = "straight")
par(mfrow=c(3,4))
for (j in 1:model_ncol) {
plot(model, type="property", property=getCodes(model,1)[,j],
palette.name=mpr.coolBlueHotRed,
main=model_colnames[j],
cex=0.5, shape = "straight")
}
if (!empty_nodes) {
cor <- apply(getCodes(model,1), 2, mpr.weighted.correlation, w=nb, som=model)
print(cor)
}
fecha_cnt precip longitud latitud altitud
[1,] -0.2395832 0.13790137 -0.1086807 -0.3415295 0.5538646
[2,] -0.5401854 0.08290181 -0.5233902 -0.4396042 -0.3932068
RepresentaciĂ³n de cada variable en un mapa de factores:
if (!empty_nodes) {
par(mfrow=c(1,1))
plot(cor[1,], cor[2,], xlim=c(-1,1), ylim=c(-1,1), type="n")
lines(c(-1,1),c(0,0))
lines(c(0,0),c(-1,1))
text(cor[1,], cor[2,], labels=model_colnames, cex=0.75)
symbols(0,0,circles=1,inches=F,add=T)
}
Importancia de cada variable - varianza ponderada por el tamaño de la celda:
if (!empty_nodes) {
sigma2 <- sqrt(apply(getCodes(model,1),2,function(x,effectif)
{m<-sum(effectif*(x-weighted.mean(x,effectif))^2)/(sum(effectif)-1)},
effectif=nb))
print(sort(sigma2,decreasing=T))
}
longitud latitud precip fecha_cnt altitud
0.9658578 0.9329411 0.9038007 0.8876858 0.8861468
if (!empty_nodes) {
hac <- mpr.hac(model, nb)
}
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=3)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=3)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-109.0 Min. :-189.00 Min. : 0.00
1st Qu.:13.00 1st Qu.: 144.0 1st Qu.: 45.00 1st Qu.: 0.00
Median :27.00 Median : 196.0 Median : 93.00 Median : 4.00
Mean :26.53 Mean : 200.4 Mean : 93.72 Mean : 17.01
3rd Qu.:40.00 3rd Qu.: 262.0 3rd Qu.: 145.00 3rd Qu.: 22.00
Max. :53.00 Max. : 442.0 Max. : 272.00 Max. :236.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.0000 Min. :27.82 Min. :-17.889
1st Qu.:0 1st Qu.: 0.0000 1st Qu.:39.88 1st Qu.: -4.049
Median :0 Median : 0.0000 Median :41.38 Median : -1.033
Mean :0 Mean : 0.6324 Mean :40.83 Mean : -1.521
3rd Qu.:0 3rd Qu.: 0.0000 3rd Qu.:42.24 3rd Qu.: 1.363
Max. :0 Max. :1073.0000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 58.0
Median : 316.0
Mean : 485.2
3rd Qu.: 704.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 1.0 Min. :-51.0 Min. : 0.000 Min. :0
1st Qu.:13.00 1st Qu.:211.0 1st Qu.:149.0 1st Qu.: 0.000 1st Qu.:0
Median :26.00 Median :234.0 Median :172.0 Median : 0.000 Median :0
Mean :26.29 Mean :229.7 Mean :165.3 Mean : 5.298 Mean :0
3rd Qu.:39.00 3rd Qu.:262.0 3rd Qu.:201.0 3rd Qu.: 2.000 3rd Qu.:0
Max. :53.00 Max. :384.0 Max. :263.0 Max. :155.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0 Median :28.44 Median :-16.33 Median : 33.0
Mean :0 Mean :28.35 Mean :-16.03 Mean : 368.5
3rd Qu.:0 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :0 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-58.0 Min. :-103.00 Min. :222 Min. :0
1st Qu.:10.00 1st Qu.:100.0 1st Qu.: 41.00 1st Qu.:246 1st Qu.:0
Median :40.00 Median :136.0 Median : 77.00 Median :278 Median :0
Mean :29.64 Mean :133.8 Mean : 72.47 Mean :299 Mean :0
3rd Qu.:46.00 3rd Qu.:181.0 3rd Qu.: 118.00 3rd Qu.:327 3rd Qu.:0
Max. :53.00 Max. :331.0 Max. : 217.00 Max. :690 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.78 1st Qu.: -5.600 1st Qu.: 61.0
Median : 0.000 Median :41.98 Median : -0.482 Median : 261.0
Mean : 5.451 Mean :40.77 Mean : -2.548 Mean : 707.2
3rd Qu.: 0.000 3rd Qu.:42.53 3rd Qu.: 1.099 3rd Qu.:1055.0
Max. :685.000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=4)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=4)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-31.0 Min. :-189.00 Min. : 0.00 Min. :0
1st Qu.:13.00 1st Qu.:152.0 1st Qu.: 52.00 1st Qu.: 0.00 1st Qu.:0
Median :26.00 Median :203.0 Median : 98.00 Median : 3.00 Median :0
Mean :26.52 Mean :208.5 Mean : 99.28 Mean : 15.97 Mean :0
3rd Qu.:40.00 3rd Qu.:267.0 3rd Qu.: 148.00 3rd Qu.: 20.00 3rd Qu.:0
Max. :53.00 Max. :442.0 Max. : 272.00 Max. :236.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:39.56 1st Qu.: -4.488 1st Qu.: 52.0
Median : 0.0000 Median :41.29 Median : -1.293 Median : 258.0
Mean : 0.0771 Mean :40.73 Mean : -1.677 Mean : 367.7
3rd Qu.: 0.0000 3rd Qu.:42.12 3rd Qu.: 1.296 3rd Qu.: 639.0
Max. :599.0000 Max. :43.57 Max. : 4.216 Max. :2371.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-109.0 Min. :-175.00 Min. : 0.00
1st Qu.:14.00 1st Qu.: 30.0 1st Qu.: -32.00 1st Qu.: 3.00
Median :27.00 Median : 78.0 Median : 11.00 Median : 18.00
Mean :26.81 Mean : 84.4 Mean : 14.45 Mean : 31.78
3rd Qu.:40.00 3rd Qu.: 138.0 3rd Qu.: 63.00 3rd Qu.: 47.00
Max. :53.00 Max. : 299.0 Max. : 183.00 Max. :225.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :28.31 Min. :-16.4992
1st Qu.:0 1st Qu.: 0.000 1st Qu.:42.18 1st Qu.: 0.7317
Median :0 Median : 0.000 Median :42.47 Median : 1.0544
Mean :0 Mean : 8.542 Mean :42.23 Mean : 0.7103
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.64 3rd Qu.: 1.7150
Max. :0 Max. :1073.000 Max. :42.77 Max. : 2.4378
altitud
Min. :1097
1st Qu.:1971
Median :2230
Mean :2159
3rd Qu.:2400
Max. :2535
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 1.0 Min. :-51.0 Min. : 0.000 Min. :0
1st Qu.:13.00 1st Qu.:211.0 1st Qu.:149.0 1st Qu.: 0.000 1st Qu.:0
Median :26.00 Median :234.0 Median :172.0 Median : 0.000 Median :0
Mean :26.29 Mean :229.7 Mean :165.3 Mean : 5.298 Mean :0
3rd Qu.:39.00 3rd Qu.:262.0 3rd Qu.:201.0 3rd Qu.: 2.000 3rd Qu.:0
Max. :53.00 Max. :384.0 Max. :263.0 Max. :155.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0 Median :28.44 Median :-16.33 Median : 33.0
Mean :0 Mean :28.35 Mean :-16.03 Mean : 368.5
3rd Qu.:0 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :0 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-58.0 Min. :-103.00 Min. :222 Min. :0
1st Qu.:10.00 1st Qu.:100.0 1st Qu.: 41.00 1st Qu.:246 1st Qu.:0
Median :40.00 Median :136.0 Median : 77.00 Median :278 Median :0
Mean :29.64 Mean :133.8 Mean : 72.47 Mean :299 Mean :0
3rd Qu.:46.00 3rd Qu.:181.0 3rd Qu.: 118.00 3rd Qu.:327 3rd Qu.:0
Max. :53.00 Max. :331.0 Max. : 217.00 Max. :690 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.78 1st Qu.: -5.600 1st Qu.: 61.0
Median : 0.000 Median :41.98 Median : -0.482 Median : 261.0
Mean : 5.451 Mean :40.77 Mean : -2.548 Mean : 707.2
3rd Qu.: 0.000 3rd Qu.:42.53 3rd Qu.: 1.099 3rd Qu.:1055.0
Max. :685.000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=5)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=5)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-31.0 Min. :-189.00 Min. : 0.00 Min. :0
1st Qu.:14.00 1st Qu.:154.0 1st Qu.: 51.00 1st Qu.: 0.00 1st Qu.:0
Median :27.00 Median :206.0 Median : 99.00 Median : 3.00 Median :0
Mean :26.73 Mean :210.3 Mean : 99.84 Mean : 12.44 Mean :0
3rd Qu.:40.00 3rd Qu.:269.0 3rd Qu.: 150.00 3rd Qu.: 17.00 3rd Qu.:0
Max. :53.00 Max. :442.0 Max. : 272.00 Max. :131.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-8.624 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:39.49 1st Qu.:-4.127 1st Qu.: 52.0
Median : 0.00000 Median :41.22 Median :-1.229 Median : 261.0
Mean : 0.05786 Mean :40.71 Mean :-1.633 Mean : 370.8
3rd Qu.: 0.00000 3rd Qu.:42.08 3rd Qu.: 1.296 3rd Qu.: 639.0
Max. :299.00000 Max. :43.57 Max. : 4.216 Max. :1405.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-109.0 Min. :-175.00 Min. : 0.00
1st Qu.:14.00 1st Qu.: 30.0 1st Qu.: -32.00 1st Qu.: 3.00
Median :27.00 Median : 78.0 Median : 11.00 Median : 18.00
Mean :26.81 Mean : 84.4 Mean : 14.45 Mean : 31.78
3rd Qu.:40.00 3rd Qu.: 138.0 3rd Qu.: 63.00 3rd Qu.: 47.00
Max. :53.00 Max. : 299.0 Max. : 183.00 Max. :225.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :28.31 Min. :-16.4992
1st Qu.:0 1st Qu.: 0.000 1st Qu.:42.18 1st Qu.: 0.7317
Median :0 Median : 0.000 Median :42.47 Median : 1.0544
Mean :0 Mean : 8.542 Mean :42.23 Mean : 0.7103
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.64 3rd Qu.: 1.7150
Max. :0 Max. :1073.000 Max. :42.77 Max. : 2.4378
altitud
Min. :1097
1st Qu.:1971
Median :2230
Mean :2159
3rd Qu.:2400
Max. :2535
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-13.0 Min. :-44.0 Min. : 55.0 Min. :0
1st Qu.: 8.00 1st Qu.:126.0 1st Qu.: 56.0 1st Qu.: 85.0 1st Qu.:0
Median :15.00 Median :154.0 Median : 81.0 Median :112.0 Median :0
Mean :20.26 Mean :158.3 Mean : 83.1 Mean :118.2 Mean :0
3rd Qu.:36.00 3rd Qu.:187.0 3rd Qu.:111.0 3rd Qu.:144.0 3rd Qu.:0
Max. :53.00 Max. :407.0 Max. :228.0 Max. :236.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.80 1st Qu.: -6.0556 1st Qu.: 42.0
Median : 0.000 Median :42.11 Median : -2.9056 Median : 143.0
Mean : 0.633 Mean :41.33 Mean : -2.9515 Mean : 278.2
3rd Qu.: 0.000 3rd Qu.:43.12 3rd Qu.: 0.8192 3rd Qu.: 421.0
Max. :599.000 Max. :43.57 Max. : 4.2156 Max. :2371.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 1.0 Min. :-51.0 Min. : 0.000 Min. :0
1st Qu.:13.00 1st Qu.:211.0 1st Qu.:149.0 1st Qu.: 0.000 1st Qu.:0
Median :26.00 Median :234.0 Median :172.0 Median : 0.000 Median :0
Mean :26.29 Mean :229.7 Mean :165.3 Mean : 5.298 Mean :0
3rd Qu.:39.00 3rd Qu.:262.0 3rd Qu.:201.0 3rd Qu.: 2.000 3rd Qu.:0
Max. :53.00 Max. :384.0 Max. :263.0 Max. :155.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0 Median :28.44 Median :-16.33 Median : 33.0
Mean :0 Mean :28.35 Mean :-16.03 Mean : 368.5
3rd Qu.:0 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :0 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-58.0 Min. :-103.00 Min. :222 Min. :0
1st Qu.:10.00 1st Qu.:100.0 1st Qu.: 41.00 1st Qu.:246 1st Qu.:0
Median :40.00 Median :136.0 Median : 77.00 Median :278 Median :0
Mean :29.64 Mean :133.8 Mean : 72.47 Mean :299 Mean :0
3rd Qu.:46.00 3rd Qu.:181.0 3rd Qu.: 118.00 3rd Qu.:327 3rd Qu.:0
Max. :53.00 Max. :331.0 Max. : 217.00 Max. :690 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.78 1st Qu.: -5.600 1st Qu.: 61.0
Median : 0.000 Median :41.98 Median : -0.482 Median : 261.0
Mean : 5.451 Mean :40.77 Mean : -2.548 Mean : 707.2
3rd Qu.: 0.000 3rd Qu.:42.53 3rd Qu.: 1.099 3rd Qu.:1055.0
Max. :685.000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=6)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=6)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-31.0 Min. :-155.0 Min. : 0.00 Min. :0
1st Qu.:25.00 1st Qu.:173.0 1st Qu.: 76.0 1st Qu.: 0.00 1st Qu.:0
Median :34.00 Median :234.0 Median : 123.0 Median : 2.00 Median :0
Mean :33.43 Mean :229.6 Mean : 118.4 Mean : 11.92 Mean :0
3rd Qu.:44.00 3rd Qu.:288.0 3rd Qu.: 165.0 3rd Qu.: 16.00 3rd Qu.:0
Max. :53.00 Max. :442.0 Max. : 272.0 Max. :131.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-8.624 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:39.47 1st Qu.:-5.598 1st Qu.: 44.0
Median : 0.00000 Median :41.22 Median :-2.138 Median : 192.0
Mean : 0.03019 Mean :40.62 Mean :-2.207 Mean : 339.4
3rd Qu.: 0.00000 3rd Qu.:42.22 3rd Qu.: 1.039 3rd Qu.: 609.0
Max. :290.00000 Max. :43.57 Max. : 4.216 Max. :1405.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-109.0 Min. :-175.00 Min. : 0.00
1st Qu.:14.00 1st Qu.: 30.0 1st Qu.: -32.00 1st Qu.: 3.00
Median :27.00 Median : 78.0 Median : 11.00 Median : 18.00
Mean :26.81 Mean : 84.4 Mean : 14.45 Mean : 31.78
3rd Qu.:40.00 3rd Qu.: 138.0 3rd Qu.: 63.00 3rd Qu.: 47.00
Max. :53.00 Max. : 299.0 Max. : 183.00 Max. :225.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :28.31 Min. :-16.4992
1st Qu.:0 1st Qu.: 0.000 1st Qu.:42.18 1st Qu.: 0.7317
Median :0 Median : 0.000 Median :42.47 Median : 1.0544
Mean :0 Mean : 8.542 Mean :42.23 Mean : 0.7103
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.64 3rd Qu.: 1.7150
Max. :0 Max. :1073.000 Max. :42.77 Max. : 2.4378
altitud
Min. :1097
1st Qu.:1971
Median :2230
Mean :2159
3rd Qu.:2400
Max. :2535
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-13.0 Min. :-44.0 Min. : 55.0 Min. :0
1st Qu.: 8.00 1st Qu.:126.0 1st Qu.: 56.0 1st Qu.: 85.0 1st Qu.:0
Median :15.00 Median :154.0 Median : 81.0 Median :112.0 Median :0
Mean :20.26 Mean :158.3 Mean : 83.1 Mean :118.2 Mean :0
3rd Qu.:36.00 3rd Qu.:187.0 3rd Qu.:111.0 3rd Qu.:144.0 3rd Qu.:0
Max. :53.00 Max. :407.0 Max. :228.0 Max. :236.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.80 1st Qu.: -6.0556 1st Qu.: 42.0
Median : 0.000 Median :42.11 Median : -2.9056 Median : 143.0
Mean : 0.633 Mean :41.33 Mean : -2.9515 Mean : 278.2
3rd Qu.: 0.000 3rd Qu.:43.12 3rd Qu.: 0.8192 3rd Qu.: 421.0
Max. :599.000 Max. :43.57 Max. : 4.2156 Max. :2371.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-22.0 Min. :-189.00 Min. : 0.00 Min. :0
1st Qu.: 6.00 1st Qu.:128.0 1st Qu.: 21.00 1st Qu.: 0.00 1st Qu.:0
Median :11.00 Median :163.0 Median : 54.00 Median : 5.00 Median :0
Mean :11.06 Mean :165.2 Mean : 56.37 Mean :13.65 Mean :0
3rd Qu.:16.00 3rd Qu.:200.0 3rd Qu.: 88.00 3rd Qu.:21.00 3rd Qu.:0
Max. :31.00 Max. :380.0 Max. : 249.00 Max. :93.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :36.85 Min. :-6.6000 Min. : 1
1st Qu.: 0.0000 1st Qu.:40.30 1st Qu.:-1.8853 1st Qu.: 71
Median : 0.0000 Median :41.29 Median : 0.5356 Median : 421
Mean : 0.1225 Mean :40.92 Mean :-0.2914 Mean : 444
3rd Qu.: 0.0000 3rd Qu.:41.91 3rd Qu.: 1.7678 3rd Qu.: 775
Max. :299.0000 Max. :43.49 Max. : 4.2156 Max. :1405
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 1.0 Min. :-51.0 Min. : 0.000 Min. :0
1st Qu.:13.00 1st Qu.:211.0 1st Qu.:149.0 1st Qu.: 0.000 1st Qu.:0
Median :26.00 Median :234.0 Median :172.0 Median : 0.000 Median :0
Mean :26.29 Mean :229.7 Mean :165.3 Mean : 5.298 Mean :0
3rd Qu.:39.00 3rd Qu.:262.0 3rd Qu.:201.0 3rd Qu.: 2.000 3rd Qu.:0
Max. :53.00 Max. :384.0 Max. :263.0 Max. :155.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0 Median :28.44 Median :-16.33 Median : 33.0
Mean :0 Mean :28.35 Mean :-16.03 Mean : 368.5
3rd Qu.:0 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :0 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-58.0 Min. :-103.00 Min. :222 Min. :0
1st Qu.:10.00 1st Qu.:100.0 1st Qu.: 41.00 1st Qu.:246 1st Qu.:0
Median :40.00 Median :136.0 Median : 77.00 Median :278 Median :0
Mean :29.64 Mean :133.8 Mean : 72.47 Mean :299 Mean :0
3rd Qu.:46.00 3rd Qu.:181.0 3rd Qu.: 118.00 3rd Qu.:327 3rd Qu.:0
Max. :53.00 Max. :331.0 Max. : 217.00 Max. :690 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.78 1st Qu.: -5.600 1st Qu.: 61.0
Median : 0.000 Median :41.98 Median : -0.482 Median : 261.0
Mean : 5.451 Mean :40.77 Mean : -2.548 Mean : 707.2
3rd Qu.: 0.000 3rd Qu.:42.53 3rd Qu.: 1.099 3rd Qu.:1055.0
Max. :685.000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=8)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=8)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. :18.00 Min. :-31.0 Min. :-155.0 Min. : 0.000 Min. :0
1st Qu.:28.00 1st Qu.:182.0 1st Qu.: 73.0 1st Qu.: 0.000 1st Qu.:0
Median :36.00 Median :254.0 Median : 126.0 Median : 1.000 Median :0
Mean :36.13 Mean :238.1 Mean : 118.7 Mean : 5.973 Mean :0
3rd Qu.:45.00 3rd Qu.:297.0 3rd Qu.: 169.0 3rd Qu.: 9.000 3rd Qu.:0
Max. :53.00 Max. :428.0 Max. : 272.0 Max. :60.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :36.85 Min. :-6.6000 Min. : 1
1st Qu.: 0.00000 1st Qu.:40.47 1st Qu.:-2.4831 1st Qu.: 79
Median : 0.00000 Median :41.29 Median : 0.4914 Median : 427
Mean : 0.02518 Mean :41.03 Mean :-0.4505 Mean : 445
3rd Qu.: 0.00000 3rd Qu.:41.81 3rd Qu.: 1.6531 3rd Qu.: 704
Max. :290.00000 Max. :43.36 Max. : 4.2156 Max. :1405
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-109.0 Min. :-175.00 Min. : 0.00
1st Qu.:14.00 1st Qu.: 30.0 1st Qu.: -32.00 1st Qu.: 3.00
Median :27.00 Median : 78.0 Median : 11.00 Median : 18.00
Mean :26.81 Mean : 84.4 Mean : 14.45 Mean : 31.78
3rd Qu.:40.00 3rd Qu.: 138.0 3rd Qu.: 63.00 3rd Qu.: 47.00
Max. :53.00 Max. : 299.0 Max. : 183.00 Max. :225.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :28.31 Min. :-16.4992
1st Qu.:0 1st Qu.: 0.000 1st Qu.:42.18 1st Qu.: 0.7317
Median :0 Median : 0.000 Median :42.47 Median : 1.0544
Mean :0 Mean : 8.542 Mean :42.23 Mean : 0.7103
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.64 3rd Qu.: 1.7150
Max. :0 Max. :1073.000 Max. :42.77 Max. : 2.4378
altitud
Min. :1097
1st Qu.:1971
Median :2230
Mean :2159
3rd Qu.:2400
Max. :2535
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. :24.00 Min. : 14.0 Min. :-61.0 Min. : 30.00 Min. :0
1st Qu.:38.00 1st Qu.:149.0 1st Qu.: 73.0 1st Qu.: 49.00 1st Qu.:0
Median :43.00 Median :191.0 Median :108.0 Median : 62.00 Median :0
Mean :42.27 Mean :194.1 Mean :108.4 Mean : 66.87 Mean :0
3rd Qu.:47.00 3rd Qu.:238.0 3rd Qu.:145.0 3rd Qu.: 82.00 3rd Qu.:0
Max. :53.00 Max. :376.0 Max. :247.0 Max. :131.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-8.624 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:40.82 1st Qu.:-5.346 1st Qu.: 52.0
Median : 0.00000 Median :41.70 Median :-1.117 Median : 192.0
Mean : 0.08761 Mean :41.40 Mean :-1.696 Mean : 311.6
3rd Qu.: 0.00000 3rd Qu.:42.56 3rd Qu.: 1.768 3rd Qu.: 513.0
Max. :52.00000 Max. :43.57 Max. : 4.216 Max. :1405.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-13.0 Min. :-44.0 Min. : 55.0 Min. :0
1st Qu.: 8.00 1st Qu.:126.0 1st Qu.: 56.0 1st Qu.: 85.0 1st Qu.:0
Median :15.00 Median :154.0 Median : 81.0 Median :112.0 Median :0
Mean :20.26 Mean :158.3 Mean : 83.1 Mean :118.2 Mean :0
3rd Qu.:36.00 3rd Qu.:187.0 3rd Qu.:111.0 3rd Qu.:144.0 3rd Qu.:0
Max. :53.00 Max. :407.0 Max. :228.0 Max. :236.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.80 1st Qu.: -6.0556 1st Qu.: 42.0
Median : 0.000 Median :42.11 Median : -2.9056 Median : 143.0
Mean : 0.633 Mean :41.33 Mean : -2.9515 Mean : 278.2
3rd Qu.: 0.000 3rd Qu.:43.12 3rd Qu.: 0.8192 3rd Qu.: 421.0
Max. :599.000 Max. :43.57 Max. : 4.2156 Max. :2371.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-22.0 Min. :-189.00 Min. : 0.00 Min. :0
1st Qu.: 6.00 1st Qu.:128.0 1st Qu.: 21.00 1st Qu.: 0.00 1st Qu.:0
Median :11.00 Median :163.0 Median : 54.00 Median : 5.00 Median :0
Mean :11.06 Mean :165.2 Mean : 56.37 Mean :13.65 Mean :0
3rd Qu.:16.00 3rd Qu.:200.0 3rd Qu.: 88.00 3rd Qu.:21.00 3rd Qu.:0
Max. :31.00 Max. :380.0 Max. : 249.00 Max. :93.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :36.85 Min. :-6.6000 Min. : 1
1st Qu.: 0.0000 1st Qu.:40.30 1st Qu.:-1.8853 1st Qu.: 71
Median : 0.0000 Median :41.29 Median : 0.5356 Median : 421
Mean : 0.1225 Mean :40.92 Mean :-0.2914 Mean : 444
3rd Qu.: 0.0000 3rd Qu.:41.91 3rd Qu.: 1.7678 3rd Qu.: 775
Max. :299.0000 Max. :43.49 Max. : 4.2156 Max. :1405
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 46.0 Min. :-68.0 Min. : 0.00 Min. :0
1st Qu.:14.00 1st Qu.:172.0 1st Qu.: 81.0 1st Qu.: 0.00 1st Qu.:0
Median :26.00 Median :214.0 Median :122.0 Median : 2.00 Median :0
Mean :25.99 Mean :221.4 Mean :120.4 Mean :10.41 Mean :0
3rd Qu.:38.00 3rd Qu.:264.0 3rd Qu.:161.0 3rd Qu.:17.00 3rd Qu.:0
Max. :53.00 Max. :442.0 Max. :269.0 Max. :68.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-8.624 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:36.75 1st Qu.:-6.909 1st Qu.: 22.0
Median : 0.00000 Median :37.84 Median :-5.879 Median : 87.0
Mean : 0.02622 Mean :39.63 Mean :-5.797 Mean :137.8
3rd Qu.: 0.00000 3rd Qu.:43.30 3rd Qu.:-4.488 3rd Qu.:185.0
Max. :177.00000 Max. :43.57 Max. :-1.169 Max. :656.0
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 1.0 Min. :-51.0 Min. : 0.000 Min. :0
1st Qu.:13.00 1st Qu.:211.0 1st Qu.:149.0 1st Qu.: 0.000 1st Qu.:0
Median :26.00 Median :234.0 Median :172.0 Median : 0.000 Median :0
Mean :26.29 Mean :229.7 Mean :165.3 Mean : 5.298 Mean :0
3rd Qu.:39.00 3rd Qu.:262.0 3rd Qu.:201.0 3rd Qu.: 2.000 3rd Qu.:0
Max. :53.00 Max. :384.0 Max. :263.0 Max. :155.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0 Median :28.44 Median :-16.33 Median : 33.0
Mean :0 Mean :28.35 Mean :-16.03 Mean : 368.5
3rd Qu.:0 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :0 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-58.0 Min. :-103.00 Min. :222 Min. :0
1st Qu.:10.00 1st Qu.:100.0 1st Qu.: 41.00 1st Qu.:246 1st Qu.:0
Median :40.00 Median :136.0 Median : 77.00 Median :278 Median :0
Mean :29.64 Mean :133.8 Mean : 72.47 Mean :299 Mean :0
3rd Qu.:46.00 3rd Qu.:181.0 3rd Qu.: 118.00 3rd Qu.:327 3rd Qu.:0
Max. :53.00 Max. :331.0 Max. : 217.00 Max. :690 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.78 1st Qu.: -5.600 1st Qu.: 61.0
Median : 0.000 Median :41.98 Median : -0.482 Median : 261.0
Mean : 5.451 Mean :40.77 Mean : -2.548 Mean : 707.2
3rd Qu.: 0.000 3rd Qu.:42.53 3rd Qu.: 1.099 3rd Qu.:1055.0
Max. :685.000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=10)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=10)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
df.cluster09 <- subset(df, cluster==9)
df.cluster10 <- subset(df, cluster==10)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster09 <- select(df.cluster09, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster10 <- select(df.cluster10, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. :18.00 Min. :-31.0 Min. :-155.0 Min. : 0.000 Min. :0
1st Qu.:28.00 1st Qu.:182.0 1st Qu.: 73.0 1st Qu.: 0.000 1st Qu.:0
Median :36.00 Median :254.0 Median : 126.0 Median : 1.000 Median :0
Mean :36.13 Mean :238.1 Mean : 118.7 Mean : 5.973 Mean :0
3rd Qu.:45.00 3rd Qu.:297.0 3rd Qu.: 169.0 3rd Qu.: 9.000 3rd Qu.:0
Max. :53.00 Max. :428.0 Max. : 272.0 Max. :60.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :36.85 Min. :-6.6000 Min. : 1
1st Qu.: 0.00000 1st Qu.:40.47 1st Qu.:-2.4831 1st Qu.: 79
Median : 0.00000 Median :41.29 Median : 0.4914 Median : 427
Mean : 0.02518 Mean :41.03 Mean :-0.4505 Mean : 445
3rd Qu.: 0.00000 3rd Qu.:41.81 3rd Qu.: 1.6531 3rd Qu.: 704
Max. :290.00000 Max. :43.36 Max. : 4.2156 Max. :1405
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-109.00 Min. :-175.00 Min. : 0.00
1st Qu.:13.00 1st Qu.: 33.00 1st Qu.: -30.00 1st Qu.: 1.00
Median :28.00 Median : 82.00 Median : 14.00 Median :12.00
Mean :26.84 Mean : 87.99 Mean : 16.76 Mean :17.44
3rd Qu.:40.00 3rd Qu.: 143.00 3rd Qu.: 67.75 3rd Qu.:29.00
Max. :53.00 Max. : 299.00 Max. : 183.00 Max. :76.00
nevada prof_nieve longitud latitud altitud
Min. :0 Min. : 0.000 Min. :40.78 Min. :-4.0103 Min. :1572
1st Qu.:0 1st Qu.: 0.000 1st Qu.:42.18 1st Qu.: 0.7317 1st Qu.:1971
Median :0 Median : 0.000 Median :42.47 Median : 1.0544 Median :2230
Mean :0 Mean : 6.992 Mean :42.23 Mean : 0.7202 Mean :2161
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.64 3rd Qu.: 1.7150 3rd Qu.:2400
Max. :0 Max. :939.000 Max. :42.77 Max. : 2.4378 Max. :2535
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. :24.00 Min. : 14.0 Min. :-61.0 Min. : 30.00 Min. :0
1st Qu.:38.00 1st Qu.:149.0 1st Qu.: 73.0 1st Qu.: 49.00 1st Qu.:0
Median :43.00 Median :191.0 Median :108.0 Median : 62.00 Median :0
Mean :42.27 Mean :194.1 Mean :108.4 Mean : 66.87 Mean :0
3rd Qu.:47.00 3rd Qu.:238.0 3rd Qu.:145.0 3rd Qu.: 82.00 3rd Qu.:0
Max. :53.00 Max. :376.0 Max. :247.0 Max. :131.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-8.624 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:40.82 1st Qu.:-5.346 1st Qu.: 52.0
Median : 0.00000 Median :41.70 Median :-1.117 Median : 192.0
Mean : 0.08761 Mean :41.40 Mean :-1.696 Mean : 311.6
3rd Qu.: 0.00000 3rd Qu.:42.56 3rd Qu.: 1.768 3rd Qu.: 513.0
Max. :52.00000 Max. :43.57 Max. : 4.216 Max. :1405.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-13.0 Min. :-44.0 Min. : 55.0 Min. :0
1st Qu.: 8.00 1st Qu.:126.0 1st Qu.: 56.0 1st Qu.: 85.0 1st Qu.:0
Median :15.00 Median :154.0 Median : 81.0 Median :112.0 Median :0
Mean :20.26 Mean :158.3 Mean : 83.1 Mean :118.2 Mean :0
3rd Qu.:36.00 3rd Qu.:187.0 3rd Qu.:111.0 3rd Qu.:144.0 3rd Qu.:0
Max. :53.00 Max. :407.0 Max. :228.0 Max. :236.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.80 1st Qu.: -6.0556 1st Qu.: 42.0
Median : 0.000 Median :42.11 Median : -2.9056 Median : 143.0
Mean : 0.633 Mean :41.33 Mean : -2.9515 Mean : 278.2
3rd Qu.: 0.000 3rd Qu.:43.12 3rd Qu.: 0.8192 3rd Qu.: 421.0
Max. :599.000 Max. :43.57 Max. : 4.2156 Max. :2371.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-22.0 Min. :-189.00 Min. : 0.00 Min. :0
1st Qu.: 6.00 1st Qu.:128.0 1st Qu.: 21.00 1st Qu.: 0.00 1st Qu.:0
Median :11.00 Median :163.0 Median : 54.00 Median : 5.00 Median :0
Mean :11.06 Mean :165.2 Mean : 56.37 Mean :13.65 Mean :0
3rd Qu.:16.00 3rd Qu.:200.0 3rd Qu.: 88.00 3rd Qu.:21.00 3rd Qu.:0
Max. :31.00 Max. :380.0 Max. : 249.00 Max. :93.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :36.85 Min. :-6.6000 Min. : 1
1st Qu.: 0.0000 1st Qu.:40.30 1st Qu.:-1.8853 1st Qu.: 71
Median : 0.0000 Median :41.29 Median : 0.5356 Median : 421
Mean : 0.1225 Mean :40.92 Mean :-0.2914 Mean : 444
3rd Qu.: 0.0000 3rd Qu.:41.91 3rd Qu.: 1.7678 3rd Qu.: 775
Max. :299.0000 Max. :43.49 Max. : 4.2156 Max. :1405
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 46.0 Min. :-68.0 Min. : 0.0 Min. :0
1st Qu.:14.00 1st Qu.:155.0 1st Qu.: 72.0 1st Qu.: 1.0 1st Qu.:0
Median :25.00 Median :198.0 Median :107.0 Median :10.0 Median :0
Mean :25.23 Mean :196.5 Mean :104.6 Mean :14.8 Mean :0
3rd Qu.:36.00 3rd Qu.:233.0 3rd Qu.:142.0 3rd Qu.:24.0 3rd Qu.:0
Max. :53.00 Max. :398.0 Max. :216.0 Max. :65.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :39.47 Min. :-8.624 Min. : 4
1st Qu.: 0.00000 1st Qu.:42.56 1st Qu.:-8.411 1st Qu.: 52
Median : 0.00000 Median :43.31 Median :-6.600 Median :127
Mean : 0.05589 Mean :43.08 Mean :-6.517 Mean :181
3rd Qu.: 0.00000 3rd Qu.:43.43 3rd Qu.:-5.698 3rd Qu.:336
Max. :177.00000 Max. :43.57 Max. :-1.636 Max. :656
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 73.0 Min. :-65.0 Min. : 0.000 Min. :0
1st Qu.:14.00 1st Qu.:183.0 1st Qu.: 91.0 1st Qu.: 0.000 1st Qu.:0
Median :27.00 Median :233.0 Median :134.0 Median : 0.000 Median :0
Mean :26.56 Mean :240.5 Mean :132.3 Mean : 7.059 Mean :0
3rd Qu.:39.00 3rd Qu.:293.0 3rd Qu.:180.0 3rd Qu.: 8.000 3rd Qu.:0
Max. :53.00 Max. :442.0 Max. :269.0 Max. :68.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000000 Min. :35.28 Min. :-6.949 Min. : 1
1st Qu.: 0.000000 1st Qu.:36.64 1st Qu.:-6.257 1st Qu.: 21
Median : 0.000000 Median :36.85 Median :-5.600 Median : 34
Mean : 0.003605 Mean :36.99 Mean :-5.248 Mean :105
3rd Qu.: 0.000000 3rd Qu.:37.28 3rd Qu.:-4.488 3rd Qu.: 90
Max. :13.000000 Max. :39.47 Max. :-1.169 Max. :582
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 1.0 Min. :-51.0 Min. : 0.000 Min. :0
1st Qu.:13.00 1st Qu.:211.0 1st Qu.:149.0 1st Qu.: 0.000 1st Qu.:0
Median :26.00 Median :234.0 Median :172.0 Median : 0.000 Median :0
Mean :26.29 Mean :229.7 Mean :165.3 Mean : 5.298 Mean :0
3rd Qu.:39.00 3rd Qu.:262.0 3rd Qu.:201.0 3rd Qu.: 2.000 3rd Qu.:0
Max. :53.00 Max. :384.0 Max. :263.0 Max. :155.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0 Median :28.44 Median :-16.33 Median : 33.0
Mean :0 Mean :28.35 Mean :-16.03 Mean : 368.5
3rd Qu.:0 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :0 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster09)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-69.00 Min. :-131.000 Min. : 54.00
1st Qu.:16.00 1st Qu.: 18.00 1st Qu.: -40.000 1st Qu.: 73.00
Median :24.00 Median : 61.00 Median : 2.000 Median : 90.00
Mean :26.66 Mean : 67.67 Mean : 3.735 Mean : 98.54
3rd Qu.:40.00 3rd Qu.:111.00 3rd Qu.: 45.000 3rd Qu.:117.00
Max. :53.00 Max. :262.00 Max. : 153.000 Max. :225.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.00 Min. :28.31 Min. :-16.4992
1st Qu.:0 1st Qu.: 0.00 1st Qu.:42.18 1st Qu.: 0.7789
Median :0 Median : 0.00 Median :42.47 Median : 1.0544
Mean :0 Mean : 15.76 Mean :42.21 Mean : 0.6641
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:42.64 3rd Qu.: 1.7150
Max. :0 Max. :1073.00 Max. :42.77 Max. : 2.4378
altitud
Min. :1097
1st Qu.:1894
Median :2247
Mean :2154
3rd Qu.:2400
Max. :2535
if (!empty_nodes) summary(df.cluster10)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-58.0 Min. :-103.00 Min. :222 Min. :0
1st Qu.:10.00 1st Qu.:100.0 1st Qu.: 41.00 1st Qu.:246 1st Qu.:0
Median :40.00 Median :136.0 Median : 77.00 Median :278 Median :0
Mean :29.64 Mean :133.8 Mean : 72.47 Mean :299 Mean :0
3rd Qu.:46.00 3rd Qu.:181.0 3rd Qu.: 118.00 3rd Qu.:327 3rd Qu.:0
Max. :53.00 Max. :331.0 Max. : 217.00 Max. :690 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.78 1st Qu.: -5.600 1st Qu.: 61.0
Median : 0.000 Median :41.98 Median : -0.482 Median : 261.0
Mean : 5.451 Mean :40.77 Mean : -2.548 Mean : 707.2
3rd Qu.: 0.000 3rd Qu.:42.53 3rd Qu.: 1.099 3rd Qu.:1055.0
Max. :685.000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1], dim(df.cluster09)[1], dim(df.cluster10)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08", "cluster09", "cluster10"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.hist(df.cluster09)
if (!empty_nodes) mpr.hist(df.cluster10)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster09)
if (!empty_nodes) mpr.boxplot(df.cluster10)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
df.cluster09.grouped <- mpr.group_by_geo(df.cluster09)
df.cluster10.grouped <- mpr.group_by_geo(df.cluster10)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster09.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster10.grouped)